package cn.yllr.tomgxianghui.controller.admin;
import cn.yllr.tomgxianghui.entity.Dishes;
import cn.yllr.tomgxianghui.entity.Raw;
import cn.yllr.tomgxianghui.entity.User;
import cn.yllr.tomgxianghui.service.DishesService;
import cn.yllr.tomgxianghui.service.RawService;
import cn.yllr.tomgxianghui.service.UserService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

//查找
@RestController
public class SearchController {
    //搜索菜品
    @Resource
    DishesService dishesService;
    @RequestMapping("/toSearchDishes")
    public String toSearchDishes(String search){
        Dishes dishes= dishesService.queryByName(search);
        if (dishes!=null){
            return "location.href='/searchDishes/"+dishes.getFoodid()+"';";
        }else {
            return "alert('404：没有找到该菜品！');";
        }
    }
    //搜索原材料
    @Resource
    RawService rawService;
    @RequestMapping("/toSearchRaws")
    public String toSearchRaws(String search){
        Raw raw= rawService.queryByName(search);
        if (raw!=null){
            return "location.href='/searchRaws/"+raw.getId()+"';";
        }else {
            return "alert('404：没有找到该原材料！');";
        }
    }

    //搜索用户
    @Resource
    UserService userService;
    @RequestMapping("/toSearchUser")
    public String toSearchUser(String search){
        User user=userService.queryById(search);
        if (user!=null){
            return "location.href='/searchUser/"+user.getAccount()+"';";
        }else {
            return "alert('404：没有找到该用户！');";
        }
    }
}
